import logging
import sys
from time import sleep

from appium import webdriver
from appium.webdriver.common.appiumby import By

sys.path.append(r'..')
from common.desired_caps import desired_caps


class BasePage():
    def __init__(self, driver):
        self.driver = driver

    def find_ele(self, loc):
        ele = self.driver.find_element(*loc)
        return ele

    def ele_input(self, loc, value, desc='输入框'):
        ele = self.find_ele(loc)
        ele.send_keys(value)
        logging.info(f'在{desc}{loc}中输入{value}成功')

    def ele_clear(self, loc, desc='输入框'):
        ele = self.find_ele(loc)
        ele.clear()
        logging.info(f'{desc}{loc}清除成功')

    def ele_click(self, loc, desc='按钮'):
        ele = self.find_ele(loc)
        ele.click()
        logging.info(f'{desc}{loc}点击成功')

if __name__ == '__main__':
    cancel_loc = (By.ID, 'android:id/button2')
    skip_loc = (By.ID, 'com.tal.kaoyan:id/tv_skip')

    driver = desired_caps()
    basepage = BasePage(driver)
    basepage.ele_click(cancel_loc, '点击取消')
    basepage.ele_click(skip_loc, '点击跳过')
    sleep(3)
    driver.quit()
